﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMPLibrary.Media
{
    public class RandomQueue
    {
        private static RandomQueue randomQueue;

        private int RANDOM_CAPACITY = 50;

        private string[] randomData;

        private int start, end;

        public static RandomQueue GetRandomQueue()
        {
            if (randomQueue == null)
                randomQueue = new RandomQueue();

            return randomQueue;
        }

        private RandomQueue()
        {
            randomData = new string[RANDOM_CAPACITY];
            start = 0;
            end = 0;
        }

        public int CurrentCapacity
        {
            get
            {
                return end;
            }
        }

        public bool IsEmpty()
        {
            return start == end;
        }

        public void Insert(string path)
        {
            if (end == RANDOM_CAPACITY)
            {
                for (int i = 0; i < RANDOM_CAPACITY; i++)
                {
                    if (i != RANDOM_CAPACITY - 1)
                        randomData[i] = randomData[i + 1];
                    else
                        randomData[i] = null;
                }
            }

            if (end >= RANDOM_CAPACITY)
                end = RANDOM_CAPACITY - 1;

            randomData[end] = path;

            end++;
        }

        public void Clear()
        {
            for (int i = 0; i < RANDOM_CAPACITY; i++)
                randomData[i] = null;

            end = 0;
        }

        public bool IsInQueue(string path)
        {
            for(int i = 0; i<end; i++)
            {
                if (randomData[i].ToLower() == path.ToLower())
                    return true;
            }

            return false;
        }
    }
}
